@{
    ViewBag.Title = "用户-角色关联";
}
@section head{
   <script type="text/javascript">
       $(document).ready(function () {
           $('.btnSearch').click(function () {
               mainSearch('.search_box :input');
           });
       });
       function on_close(key) {
           $('#details').datagrid('reload');
       }
       function onDeleteData() {
           $('#details').datagrid('reload');
       }
       function cmdformat(value, row, index) {
           var id = row.ID;
           if (id == undefined) id = row.id;
           return '<a href="javascript:Del(' + id + ',onDeleteData)">删除</a>';
       }
       function add() {
           var username = '@ViewBag.UserName';
           var rolecode = '@ViewBag.RoleCode';
           if(username!=''){
               DataDialog.Show('ManagerRole', true, true, undefined, function (ret) {
                   postModal('@Url.Action("AddRole")', { UserName: username, RoleCode: ret.result }, function (ret) {
                       if (ret.success) {
                           $('#details').datagrid('reload');
                       }
                   });
               });
           }
           else if(rolecode!=''){
               DataDialog.Show('Manager', true, true, undefined, function (ret) {
                   postModal('@Url.Action("AddUser")', { RoleCode: rolecode, UserName: ret.result }, function (ret) {
                       if (ret.success) {
                           $('#details').datagrid('reload');
                       }
                   });
               });
           }
           else {
               show_fullscreen_dialog(serverUrl.add, on_close, 'add')
           }
       }
   </script>
}
@section body{
<body style="padding:@ViewBag.Padding">
<div class="easyui-layout" data-options="fit:true">
    <div region="north" border="false">
        <div class="navigation">
            <div class="left">
                @ViewBag.CurrentPath  
            </div>
            @if(!string.IsNullOrEmpty(ViewBag.ListParams))
            {
            <a href="javascript:CloseMe();" class="back">后退</a>
            }
        </div>
        <div class="tools_box">
	        <div class="tools_bar">
                <div class="left">
                   <a href="javascript:search_click()" id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true ">查询</a>  
                   <a href="javascript:add();" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true ">添加</a>  
                   <a href="javascript:DeleteSelecteds($('#details').datagrid('getSelections'),undefined,onDeleteData)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">批量删除</a>
                </div>
            </div>
            <div class="search_box">
                @if(string.IsNullOrEmpty(ViewBag.UserName))
                {
                <span>用户账号：</span><input type="text" name="UserName" class="txtSearchInput" />
                <span>真实姓名：</span><input type="text" name="Manager.RealName" class="txtSearchInput" />              
                }
                @if(string.IsNullOrEmpty(ViewBag.RoleCode))
                {
                <span>角色代号：</span><input type="text" name="RoleCode" class="txtSearchInput" />
                <span>角色名称：</span><input type="text" name="ManagerRole.RoleName" class="txtSearchInput" />              
                }
                <input type="submit" value="查询" class="btnSearch"/>
		    </div>
        </div>
    </div> 
    <div region="center" border="false">
        <table class="easyui-datagrid" id="details" data-options="fit:true,rownumbers:true,singleSelect:false,
          pagination:true,border:true,url:serverUrl.list + '@ViewBag.ListParams'">
           <thead>  
               <tr>  
                   <th data-options="field:'ID',checkbox:true"></th>
                   @if(string.IsNullOrEmpty(ViewBag.UserName))
                   {
                   <th data-options="field:'UserName',sortable:true,width:100">用户账号</th>
                   <th data-options="field:'RealName',sortable:true,width:120">真实姓名</th>
                   }
                   @if(string.IsNullOrEmpty(ViewBag.RoleCode))
                   {
                   <th data-options="field:'RoleCode',sortable:true,width:100">角色代号</th>
                   <th data-options="field:'RoleName',sortable:true,width:120">角色名称</th>
                   }
                   <th data-options="field:'cmd',width:120,align:'center',formatter:cmdformat">操作</th>
               </tr>  
           </thead>  
        </table>
    </div>
</div>
</body>
}